package cmcshan1;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;


public class Driver  extends javax.swing.JFrame {

	public JPanel rootPane;
	public TableView tView;
	public DoctorTableView dtView;
	public NurseTableView ntView;
	public VisitTableView vtView;
	public SearchView sView;
	public DoctorSearchView dsView; 
	public NurseSearchView nsView;
	public VisitSearchView vsView;
	private String adminPassword;
	private String adminid;
	private String nursePassword;
	private String nurseid;
	public JTabbedPane tabbedpane;
	public AdministratorSqlView sqlPanel;
	
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				Driver inst = new Driver();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public Driver(){
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setSize(1040, 570);
			setDefaultCloseOperation(EXIT_ON_CLOSE);
			rootPane = new JPanel();
			tView = new TableView(this);
			dtView = new DoctorTableView(this);
			ntView = new NurseTableView(this);
			vtView = new VisitTableView(this);
			sView = new SearchView(this);
			dsView = new DoctorSearchView(this);
			nsView = new NurseSearchView(this);
			vsView = new VisitSearchView(this);
			
			tabbedpane = new JTabbedPane();
			tabbedpane.setPreferredSize(new Dimension(1020, 520));
			JPanel patientPanel = new JPanel();
			patientPanel.setLayout(new BorderLayout());
			patientPanel.add(sView, BorderLayout.NORTH);
			patientPanel.add(tView, BorderLayout.CENTER);
			tabbedpane.addTab("Patients", patientPanel);
			
			JPanel doctorPanel = new JPanel();
			doctorPanel.setLayout(new BorderLayout());
			doctorPanel.add(dsView, BorderLayout.NORTH);
			doctorPanel.add(dtView, BorderLayout.CENTER);
			tabbedpane.addTab("Doctors", doctorPanel);
			
			JPanel nursePanel = new JPanel();
			nursePanel.setLayout(new BorderLayout());
			nursePanel.add(nsView, BorderLayout.NORTH);
			nursePanel.add(ntView, BorderLayout.CENTER);
			tabbedpane.addTab("Nurses", nursePanel);
			
			JPanel visitPanel = new JPanel();
			visitPanel.setLayout(new BorderLayout());
			visitPanel.add(vsView, BorderLayout.NORTH);
			visitPanel.add(vtView, BorderLayout.CENTER);
			tabbedpane.addTab("Patient Visits", visitPanel);
			
			rootPane.add(tabbedpane);
			this.getContentPane().add(rootPane);
			
			adminPassword = "admin";
			adminid = "admin1";
			nursePassword = "nurse";
			nurseid = "nurse1";
			Object[] possibilites = {"Administrator", "Nurse"};
			boolean identified = false;
			String id = "";
			while(!identified)
			{
				id = (String)JOptionPane.showInputDialog(this, "Please identify as one of the following:", "Log In", JOptionPane.PLAIN_MESSAGE, null, possibilites, "Administrator" );
				if(id == "Administrator")
					identified = true;
				else if(id == "Nurse")
					identified = true;
			}
			
			boolean correctid = false;
			while(!correctid)
			{
				String username = (String)JOptionPane.showInputDialog(this, "Please type in your username:", "Continue", JOptionPane.PLAIN_MESSAGE, null, null, null );
				if(username != null)
				{
					if(id == "Administrator")
					{
						if(username.equals(adminid))
							correctid = true;
					}
					if(id == "Nurse")
					{
						if(username.equals(nurseid))
							correctid = true;
					}
				}
			}
			
			boolean correctpass = false;
			while(!correctpass)
			{
				String pass = (String)JOptionPane.showInputDialog(this, "Please type in your password:", "Log In", JOptionPane.PLAIN_MESSAGE, null, null, null );
				if(pass != null)
				{
					if(id == "Administrator")
					{
						if(pass.equals(adminPassword))
							correctpass = true;
							sqlPanel = new AdministratorSqlView();
							tabbedpane.add("Admin SQL Panel", sqlPanel);
					}
					if(id == "Nurse")
					{
						if(pass.equals(nursePassword))
							correctpass = true;
					}
				}
			}
		} 
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}
